package BuilderType.src;


/***
 * @Description
 * 当一个类的构造函数参数超过4个，而且这些参数有些是可选的时，我们通常有两种办法来构建它的对象。
 * 例如我们现在有如下一个类计算机类Computer，其中cpu与ram是必填参数，
 * 而其他3个是可选参数，那么我们如何构造这个类的实例呢,通常有两种常用的方式：
 * 1.构造函数方式-折叠多个构造函数
 * 2.javabean方式-get、set方法
 *
 * @Date 9:29 2022/8/8
 * @Author sunye
 **/
public class Client1 {
    public static void main(String[] args) {
        Computer1 computer1 = new Computer1("英特尔", "16g");
        System.out.println(computer1);
    }
}

class Computer1 {
    private String cpu;//必须
    private String ram;//必须
    private int usbCount;//可选
    private String keyboard;//可选
    private String display;//可选

    //折叠构造函数模式（telescoping constructor pattern ），这个我们经常用,如下代码所示
    public Computer1(String cpu, String ram) {
        this(cpu, ram, 0);
    }
    public Computer1(String cpu, String ram, int usbCount) {
        this(cpu, ram, usbCount, "罗技键盘");
    }
    public Computer1(String cpu, String ram, int usbCount, String keyboard) {
        this(cpu, ram, usbCount, keyboard, "三星显示器");
    }
    public Computer1(String cpu, String ram, int usbCount, String keyboard, String display) {
        this.cpu = cpu;
        this.ram = ram;
        this.usbCount = usbCount;
        this.keyboard = keyboard;
        this.display = display;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "cpu='" + cpu + '\'' +
                ", ram='" + ram + '\'' +
                ", usbCount=" + usbCount +
                ", keyboard='" + keyboard + '\'' +
                ", display='" + display + '\'' +
                '}';
    }
}